package lab1;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class FormMultiValuesDemo
 */
@WebServlet("/lab1/FormMultiValuesDemo")
public class FormMultiValuesDemo extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();

		out.println("<html><head><title>Result</title></head><body>");
		String[] values = request.getParameterValues("topic");
		if (values != null)
			for (int i = 0; i < values.length; i++) {
				out.println(values[i]);
			}
		else
			out.print("Select menu is null");
		out.println("<br><hr>");

		String[] checkbox = request.getParameterValues("checkbox");
		if (checkbox != null)
			for (int i = 0; i < checkbox.length; i++) {
				out.println(checkbox[i]);
			}
		else
			out.print("Checkbox list is null");
		out.println("<br><hr>");

		String[] radio = request.getParameterValues("radio");
		if (radio != null)
			for (int i = 0; i < radio.length; i++) {
				out.println(radio[i]);
			}
		else
			out.print("Radio button is null");
		out.println("</body></html>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
